﻿using MediatR;
using Traceability.Commont.Domains.ScratchTheFat;
using Traceability.Commont.DTOs.CommontFiles;
using Traceability.Commont.Infrastructures.Interfaces;
namespace U.Enterprise.Api.Applications.PartitionWarehousings
{
    public class SplitRUHtmlHandler : IRequestHandler<SplitRUHtmlCommond, PageDTO<SplitRU>>
    {

        private readonly IBateRepository<SplitRU> _SplitRU;

        public SplitRUHtmlHandler(IBateRepository<SplitRU> splitRU
            )
        {
            _SplitRU = splitRU;
        }

        public async Task<PageDTO<SplitRU>> Handle(SplitRUHtmlCommond request, CancellationToken cancellationToken)
        {
            try
            {
                var list = new PageDTO<SplitRU>() { pageCount = 0, Lists = new List<SplitRU>(), totalCount = 0 };




                var query = _SplitRU.GetAll().ToList();


                list.totalCount = query.Count;
                list.pageCount = (int)Math.Ceiling(query.Count * 1.0 / request.pagesize);


                var num = (request.pageindex - 1) / request.pagesize;


                query = query.Where(x=>x.Stoct==0).OrderBy(x => x.SplitWarehousingId).Skip(num).Take(request.pagesize).ToList();



                list.Lists = query.ToList();


                return list;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
